package com.ocom.srvpaccess.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.srvpaccess.XfDeviceInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.srvpaccess.dao.IDaoXFDeviceInfo;
import com.ocom.srvpaccess.service.XFDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class XFDeviceInfoServiceImpl extends ServiceImpl<IDaoXFDeviceInfo, XfDeviceInfo> implements XFDeviceInfoService {

    @Autowired
    private IDaoXFDeviceInfo iDaoXFDeviceInfo;

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "companyId")
    @Override
    public XfDeviceInfo getParaJobid(Long companyId, String machNo) {
        QueryWrapper<XfDeviceInfo> query = Wrappers.query();
        query.eq("com_id",companyId);
        query.eq("device_no",machNo);
        query.select("rsa_jobid");
        return iDaoXFDeviceInfo.selectOne(query);
    }

    @DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.MASTER)
    @Override
    public Boolean updateRsa(Long companyId, String machNo, String jobId) {
        UpdateWrapper<XfDeviceInfo> updateWrapper=new UpdateWrapper<>();
        updateWrapper.set("rsa_state",0);
        updateWrapper.eq("com_id",companyId);
        updateWrapper.eq("device_no",machNo);
        updateWrapper.eq("rsa_jobid",jobId);
        return this.update(updateWrapper);
    }
}
